package dao;

import java.util.List;

import org.apache.ibatis.annotations.*;

import pojo.EssayAndUser;
import pojo.Manager;
import pojo.MessageUserEssay;
import pojo.Page;

public interface ManagerDao {

	//根据用户名登录
	@Select(value="select * from manager where manager_name=#{managerName}")
	@Results({
		@Result(column="manager_id",property="managerId",id=true),
		@Result(column="manager_name",property="managerName")
	})
	public Manager selectByManagerName(String managerName);
	
	//管理者的消息页显示信息
	@Select(value="select * from managermessage limit #{currentPage},#{limitNumber}")
	@Results({
		@Result(column="manager_message_id",property="managerMessageId",id=true),
		@Result(column="sensitive_words",property="sensitiveWords"),
		@Result(column="user_id",property="userId"),
		@Result(column="essay_id",property="essayId"),
		@Result(column="user_id",property="user",one=@One(select="dao.UserMapper.selectByPrimaryKey")),
		@Result(column="essay_id",property="essay",one=@One(select="dao.EssayMapper.selectByPrimaryKey"))
	})
	public List<MessageUserEssay> selectAllMessage(Page page);

	//根据id查询文章/包括审核的筛选
	@Select(value = "select * from essay where essay_id=#{essayId} and auditing=#{auditing}")
	@Results({@Result(property = "essayId", column = "essay_id", id = true),
			@Result(property = "userId", column = "user_id"),
			@Result(property = "readNumber", column = "read_number"),
			@Result(property = "likeNumber", column = "like_number"),
			@Result(property = "treadNumber", column = "tread_number"),
			@Result(property = "commentNumber", column = "comment_number"),
			@Result(property = "publishDate", column = "publish_date"),
			@Result(property = "user", column = "user_id", one = @One(select = "dao.UserMapper.selectByPrimaryKey"))})
	public List<EssayAndUser> selectByEssayId(@Param("essayId") Integer essayId,@Param("auditing")Integer auditing);

	//根据类别/标题查询文章/包括审核的筛选
	@Select(value = "<script> " +
			"select * from essay where 1=1" +
			"<if test=\"title!=null and title!=''\">" +
			"and title like '%${title}%'" +
			"</if>" +
			"and auditing=#{auditing}" +
			" limit #{page.currentPage},#{page.limitNumber}"+
			"</script>")
	@Results({@Result(property = "essayId", column = "essay_id", id = true),
			@Result(property = "userId", column = "user_id"),
			@Result(property = "readNumber", column = "read_number"),
			@Result(property = "likeNumber", column = "like_number"),
			@Result(property = "treadNumber", column = "tread_number"),
			@Result(property = "commentNumber", column = "comment_number"),
			@Result(property = "publishDate", column = "publish_date"),
			@Result(property = "user", column = "user_id", one = @One(select = "dao.UserMapper.selectByPrimaryKey"))})
	public  List<EssayAndUser> SelectByTitle(@Param("title")String title,@Param("auditing")Integer auditing,@Param("page") Page page);


	//管理员搜索所有文章/不包括是否审核/根据文章ID
	@Select(value = "select * from essay where essay_id=#{essayId}")
	@Results({@Result(property = "essayId", column = "essay_id", id = true),
			@Result(property = "userId", column = "user_id"),
			@Result(property = "readNumber", column = "read_number"),
			@Result(property = "likeNumber", column = "like_number"),
			@Result(property = "treadNumber", column = "tread_number"),
			@Result(property = "commentNumber", column = "comment_number"),
			@Result(property = "publishDate", column = "publish_date"),
			@Result(property = "user", column = "user_id", one = @One(select = "dao.UserMapper.selectByPrimaryKey"))})
	public  List<EssayAndUser> SelectAllByEssayId(Integer essayId);

	//管理员搜索所有文章/不包括是否审核/根据文章标题
	//根据类别/标题查询文章/包括审核的筛选
	@Select(value = "<script> " +
			"select * from essay where 1=1" +
			"<if test=\"title!=null and title!=''\">" +
			"and title like '%${title}%'" +
			"</if>" +
			"limit #{page.currentPage},#{page.limitNumber}"+
			"</script>")
	@Results({@Result(property = "essayId", column = "essay_id", id = true),
			@Result(property = "userId", column = "user_id"),
			@Result(property = "readNumber", column = "read_number"),
			@Result(property = "likeNumber", column = "like_number"),
			@Result(property = "treadNumber", column = "tread_number"),
			@Result(property = "commentNumber", column = "comment_number"),
			@Result(property = "publishDate", column = "publish_date"),
			@Result(property = "user", column = "user_id", one = @One(select = "dao.UserMapper.selectByPrimaryKey"))})
	public  List<EssayAndUser> SelectAllByTitle(@Param("title")String title, @Param("page") Page page);

	//查询所有文章数量
	@Select(value = "select count(*) from essay")
	public int SelectAllEssayCount();

	//查询已审核文章数量
	@Select(value = "select count(*) from essay where auditing=1")
	public int SelectAuditingEssayCount();

	//查询未审核文章数量
	@Select(value = "select count(*) from essay where auditing=0")
	public int SelectUnAuditingEssayCount();

	//根据标题查询文章数量/所有
	@Select(value = "SELECT COUNT(*) FROM essay where title LIKE '%${title}%' ")
	public int SelectByTitleCountAll(@Param("title") String title);

	//根据标题查询文章数量/已审核
	@Select(value = "SELECT COUNT(*) FROM essay where title LIKE '%${title}%' and auditing=1")
	public int SelectByTitleCountAuditing(@Param("title")String title);

	//根据标题查询文章数量/未审核
	@Select(value = "SELECT COUNT(*) FROM essay where title LIKE '%${title}%' and auditing=0")
	public int SelectByTitleCountUnAuditing(@Param("title")String title);

	//所有用户的数量/分页使用
	@Select(value = "select count(*) from user")
	public int SelectUserCount();

	//根据用户名查询的用户数量/分页使用
	@Select(value = "select count(*) from user where user_name like '%${username}%'")
	public int SelectUserByNameCount(@Param("username") String username);

	//消息总数
	@Select(value = "select count(*) from managermessage")
	public int SelectTodayMessageCount();

	//今日发布文章总数
	@Select(value = "select count(*) from essay where publish_date =#{today}")
	public int SelectTodayEssayCount(String today);

	//所有下载帖数量
	@Select(value = "select count(*) from essay where category='downLoadEssay'")
	public int SelectAllDownloadEssayCount();

	//今日下载帖数量
	@Select(value = "select count(*) from essay where category='downLoadEssay' and publish_date=#{today}")
	public int SelectTodayDownloadEssayCount(String today);

	//今日普通贴数量
	@Select(value = "select count(*) from essay where category='commonEssay' and publish_date =#{today}")
	public int SelectTodayCommonEssayCount(String today);

	//所有普通贴的数量
	@Select(value = "select count(*) from essay where category='commonEssay'")
	public int SelectAllCommonEssayCount();

	//待审核文章总数
	@Select(value = "select count(*) from essay where auditing = 0 ")
	public int SelectEssayUnAuditingCount();


}
